package com.codeduck.bean.entity;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;

/**
 * BeanFullLifeCycle的后置处理器
 * 配置类见 {@link com.codeduck.bean.config.BeanFullLifeCycleConfig}
 *
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @createDate: 2021-12-23
 */
@Slf4j
public class BeanFullLifeCyclePostProcessor implements InstantiationAwareBeanPostProcessor {
    @Override
    public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
        if ("beanFullLifeCycle".equals(beanName)) {
            log.warn("InstantiationAwareBeanPostProcessor#postProcessBeforeInstantiation 方法已调用");
        }
        return null;
    }

    @Override
    public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
        if ("beanFullLifeCycle".equals(beanName)) {
            log.warn("InstantiationAwareBeanPostProcessor#postProcessAfterInstantiation 方法已调用");
        }
        return false;
    }

    @Override
    public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException {
        if ("beanFullLifeCycle".equals(beanName)) {
            log.warn("InstantiationAwareBeanPostProcessor#postProcessProperties 方法已调用");
        }
        return null;
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if ("beanFullLifeCycle".equals(beanName)) {
            log.warn("InstantiationAwareBeanPostProcessor#postProcessBeforeInitialization 方法已调用");
        }
        return null;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if ("beanFullLifeCycle".equals(beanName)) {
            log.warn("InstantiationAwareBeanPostProcessor#postProcessAfterInitialization 方法已调用");
        }
        return null;
    }
}
